from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings
from itsdangerous import BadSignature


def generic_verify_url(user_id, email):
    # 1.创建序列化器
    serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)
    # 2.组织数据
    data = {
        'user_id': user_id,
        'email': email
    }
    # 3.进行加密处理
    token = serializer.dumps(data)
    # 4. 返回
    return 'http://www.meiduo.site:8080/success_verify_email.html?token=%s' % token.decode()





def check_active_token(token):

    #解密
    #1、创建序列化器
    serializer = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)

    #2、对数据进行解密，解密的时候可能存在异常
    try:
        data = serializer.loads(token)
    except BadSignature:
        return None

    #3、把数据返回回去
    return data
































